/*     */ package com.zimbra.cs.util.tnef.mapi;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.util.tnef.IcalUtil;
/*     */ import com.zimbra.cs.util.tnef.TNEFtoIcalendarServiceException;
/*     */ import java.io.IOException;
/*     */ import java.text.DateFormat;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Calendar;
/*     */ import java.util.EnumSet;
/*     */ import java.util.GregorianCalendar;
/*     */ import java.util.List;
/*     */ import net.fortuna.ical4j.model.Date;
/*     */ import net.fortuna.ical4j.model.DateTime;
/*     */ import net.fortuna.ical4j.model.Property;
/*     */ import net.fortuna.ical4j.model.Recur;
/*     */ import net.fortuna.ical4j.model.WeekDayList;
/*     */ import net.fortuna.ical4j.model.property.RRule;
/*     */ import net.freeutils.tnef.RawInputStream;
/*     */ import net.freeutils.tnef.TNEFUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class RecurrenceDefinition
/*     */ {
/*  57 */   static Log sLog = ZimbraLog.tnef;
/*     */   private TimeZoneDefinition tzDef;
/*     */   
/*  60 */   public static enum RecurrenceFrequency { DAILY(8202),  WEEKLY(8203),  MONTHLY(8204),  YEARLY(8205);
/*     */     
/*     */     private final int MapiPropValue;
/*     */     
/*     */     private RecurrenceFrequency(int propValue) {
/*  65 */       this.MapiPropValue = propValue;
/*     */     }
/*     */     
/*     */     public int mapiPropValue() {
/*  69 */       return this.MapiPropValue;
/*     */     }
/*     */   }
/*     */   
/*     */   public static enum PatternType {
/*  74 */     DAY(0),  WEEK(1), 
/*  75 */     MONTH(2),  MONTH_NTH(3),  MONTH_END(4), 
/*  76 */     HJ_MONTH(10),  HJ_MONTH_NTH(11),  HJ_MONTH_END(12);
/*     */     
/*     */     private final int MapiPropValue;
/*     */     
/*     */     private PatternType(int propValue) {
/*  81 */       this.MapiPropValue = propValue;
/*     */     }
/*     */     
/*     */     public int mapiPropValue() {
/*  85 */       return this.MapiPropValue;
/*     */     }
/*     */   }
/*     */   
/*     */   public static enum EndType {
/*  90 */     END_BY_DATE(8225L), 
/*  91 */     END_AFTER_N_OCCURRENCES(8226L), 
/*  92 */     NEVER_END(8227L), 
/*  93 */     NEVER_END_OLD(-1L);
/*     */     
/*     */     private final long MapiPropValue;
/*     */     
/*     */     private EndType(long propValue) {
/*  98 */       this.MapiPropValue = propValue;
/*     */     }
/*     */     
/*     */     public long mapiPropValue() {
/* 102 */       return this.MapiPropValue;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private String oemCodePage;
/*     */   
/*     */   private long readerVersion;
/*     */   
/*     */   private long writerVersion;
/*     */   
/*     */   public RecurrenceFrequency recurrenceFrequency;
/*     */   
/*     */   public PatternType patternType;
/*     */   
/*     */   public MsCalScale calScale;
/*     */   
/*     */   private long firstDateTime;
/*     */   
/*     */   private long period;
/*     */   
/*     */   private long slidingFlag;
/*     */   
/*     */   private long dayMask;
/*     */   
/*     */   private boolean haveDayMask;
/*     */   
/*     */   private long dayOfMonth;
/*     */   
/*     */   private boolean haveDayOfMonth;
/*     */   
/*     */   private long weekDayOccurrenceNumber;
/*     */   
/*     */   private boolean haveWeekDayOccurNum;
/*     */   
/*     */   private long occurrenceCount;
/*     */   
/*     */   private EndType endType;
/*     */   
/*     */   private DayOfWeek firstDayOfWeek;
/*     */   private EnumSet<DayOfWeek> dayOfWeekMask;
/*     */   int deletedInstanceCount;
/*     */   long[] delMidnightMinsSince1601;
/*     */   int modifiedInstanceCount;
/*     */   long[] modMidnightMinsSince1601;
/*     */   private long startMinsSince1601;
/*     */   private long endMinsSince1601;
/*     */   private long readerVersion2;
/*     */   private long writerVersion2;
/*     */   private long startTimeOffset;
/*     */   private long endTimeOffset;
/*     */   private int exceptionCount;
/*     */   private long rsrvdBlock1Size;
/*     */   private byte[] rsrvdBlock1;
/*     */   private long rsrvdBlock2Size;
/*     */   private byte[] rsrvdBlock2;
/*     */   private long unprocessedByteCount;
/*     */   private byte[] unprocessedBytes;
/*     */   private List<DateTime> exdateTimes;
/*     */   private List<DateTime> rdateTimes;
/*     */   private List<ChangedInstanceInfo> changedInstances;
/*     */   public RecurrenceDefinition(RawInputStream ris, TimeZoneDefinition tz, String oemCP)
/*     */     throws IOException, TNEFtoIcalendarServiceException
/*     */   {
/* 166 */     this.oemCodePage = oemCP;
/* 167 */     this.exdateTimes = null;
/* 168 */     this.rsrvdBlock1Size = -1L;
/* 169 */     this.rsrvdBlock2Size = -1L;
/* 170 */     this.haveDayMask = false;
/* 171 */     this.haveDayOfMonth = false;
/* 172 */     this.haveWeekDayOccurNum = false;
/* 173 */     this.tzDef = tz;
/*     */     try {
/* 175 */       this.readerVersion = ris.readU16();
/* 176 */       this.writerVersion = ris.readU16();
/* 177 */       readRecurrenceFrequency(ris);
/* 178 */       readPatternType(ris);
/* 179 */       readMsCalScale(ris);
/* 180 */       readFirstDateTime(ris);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 186 */       this.period = ris.readU32();
/* 187 */       this.slidingFlag = ris.readU32();
/* 188 */       this.dayMask = 0L;
/* 189 */       this.dayOfMonth = 0L;
/* 190 */       this.weekDayOccurrenceNumber = 0L;
/*     */       
/*     */ 
/* 193 */       switch (this.patternType) {
/*     */       case DAY: 
/*     */         break;
/*     */       case WEEK: 
/* 197 */         this.dayMask = ris.readU32();
/* 198 */         this.haveDayMask = true;
/* 199 */         break;
/*     */       case MONTH: 
/*     */       case MONTH_END: 
/*     */       case HJ_MONTH: 
/*     */       case HJ_MONTH_END: 
/* 204 */         this.dayOfMonth = ris.readU32();
/* 205 */         this.haveDayOfMonth = true;
/* 206 */         break;
/*     */       case MONTH_NTH: 
/*     */       case HJ_MONTH_NTH: 
/* 209 */         this.dayMask = ris.readU32();
/* 210 */         this.haveDayMask = true;
/* 211 */         this.weekDayOccurrenceNumber = ris.readU32();
/* 212 */         this.haveWeekDayOccurNum = true;
/* 213 */         break;
/*     */       default: 
/* 215 */         throw TNEFtoIcalendarServiceException.RECURDEF_BAD_PATTERN(this.patternType.toString());
/*     */       }
/*     */       
/* 218 */       readEndType(ris);
/* 219 */       this.occurrenceCount = ris.readU32();
/* 220 */       readFirstDayOfWeek(ris);
/* 221 */       this.deletedInstanceCount = ((int)ris.readU32());
/* 222 */       this.delMidnightMinsSince1601 = new long[this.deletedInstanceCount];
/* 223 */       for (int cnt = 0; cnt < this.deletedInstanceCount; cnt++) {
/* 224 */         this.delMidnightMinsSince1601[cnt] = ris.readU32();
/*     */       }
/* 226 */       this.modifiedInstanceCount = ((int)ris.readU32());
/* 227 */       this.modMidnightMinsSince1601 = new long[this.modifiedInstanceCount];
/* 228 */       for (int cnt = 0; cnt < this.modifiedInstanceCount; cnt++) {
/* 229 */         this.modMidnightMinsSince1601[cnt] = ris.readU32();
/*     */       }
/*     */       
/* 232 */       this.startMinsSince1601 = ris.readU32();
/* 233 */       this.endMinsSince1601 = ris.readU32();
/*     */       
/* 235 */       this.unprocessedByteCount = ris.available();
/* 236 */       if (this.unprocessedByteCount == 0L)
/*     */       {
/* 238 */         this.exceptionCount = 0;
/* 239 */         this.startTimeOffset = 0L;
/* 240 */         this.endTimeOffset = 0L;
/* 241 */         this.exceptionCount = 0;
/* 242 */         this.changedInstances = new ArrayList();
/* 243 */         return;
/*     */       }
/* 245 */       this.readerVersion2 = ris.readU32();
/* 246 */       this.writerVersion2 = ris.readU32();
/*     */       
/* 248 */       this.startTimeOffset = ris.readU32();
/* 249 */       this.endTimeOffset = ris.readU32();
/* 250 */       this.exceptionCount = ris.readU16();
/*     */       
/*     */ 
/* 253 */       this.changedInstances = new ArrayList();
/* 254 */       for (int cnt = 1; cnt <= this.modifiedInstanceCount; cnt++) {
/* 255 */         ChangedInstanceInfo cInst = new ChangedInstanceInfo(cnt, this.tzDef, this.oemCodePage);
/* 256 */         cInst.readExceptionInfo(ris);
/* 257 */         this.unprocessedByteCount = ris.available();
/* 258 */         this.changedInstances.add(cInst);
/*     */       }
/* 260 */       this.unprocessedByteCount = ris.available();
/* 261 */       this.rsrvdBlock1 = null;
/* 262 */       if (this.unprocessedByteCount > 0L) {
/* 263 */         this.rsrvdBlock1Size = ris.readU32();
/* 264 */         this.rsrvdBlock1 = ris.readBytes((int)this.rsrvdBlock1Size);
/*     */       }
/* 266 */       this.unprocessedByteCount = ris.available();
/* 267 */       if (this.unprocessedByteCount == 0L) {
/* 268 */         return;
/*     */       }
/* 270 */       boolean hasChangeHL = this.writerVersion2 >= 12297L;
/* 271 */       for (ChangedInstanceInfo cInst : this.changedInstances) {
/* 272 */         cInst.readExtendedException(ris, hasChangeHL);
/*     */       }
/* 274 */       this.unprocessedByteCount = ris.available();
/* 275 */       if (this.unprocessedByteCount > 0L) {
/* 276 */         this.rsrvdBlock2Size = ris.readU32();
/* 277 */         this.rsrvdBlock2 = ris.readBytes((int)this.rsrvdBlock2Size);
/*     */       }
/* 279 */       this.unprocessedByteCount = ris.available();
/* 280 */       if (this.unprocessedByteCount > 0L) {
/* 281 */         this.unprocessedBytes = ris.readBytes((int)this.unprocessedByteCount);
/*     */       }
/*     */     } catch (IOException e) {
/* 284 */       sLog.debug("Problem processing PidLidAppointmentRecur property", e);
/* 285 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String xMicrosoftCalscale()
/*     */   {
/* 295 */     return this.calScale.XMicrosoftCalScale();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public RecurrenceFrequency getRecurrenceFrequency()
/*     */   {
/* 302 */     return this.recurrenceFrequency;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public PatternType getPatternType()
/*     */   {
/* 309 */     return this.patternType;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public MsCalScale getMsCalScale()
/*     */   {
/* 316 */     return this.calScale;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public EndType getEndType()
/*     */   {
/* 323 */     return this.endType;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public DayOfWeek getFirstDayOfWeek()
/*     */   {
/* 330 */     return this.firstDayOfWeek;
/*     */   }
/*     */   
/*     */   public DateTime getStartDate() {
/* 334 */     return IcalUtil.localMinsSince1601toDate(this.startMinsSince1601, this.tzDef);
/*     */   }
/*     */   
/*     */   public EnumSet<DayOfWeek> getDayOfWeekMask() {
/* 338 */     if (this.dayOfWeekMask != null) {
/* 339 */       return this.dayOfWeekMask;
/*     */     }
/*     */     
/* 342 */     this.dayOfWeekMask = EnumSet.noneOf(DayOfWeek.class);
/* 343 */     if (this.haveDayMask) {
/* 344 */       if ((this.dayMask & 1L) == 1L) {
/* 345 */         this.dayOfWeekMask.add(DayOfWeek.SU);
/*     */       }
/* 347 */       if ((this.dayMask & 0x2) == 2L) {
/* 348 */         this.dayOfWeekMask.add(DayOfWeek.MO);
/*     */       }
/* 350 */       if ((this.dayMask & 0x4) == 4L) {
/* 351 */         this.dayOfWeekMask.add(DayOfWeek.TU);
/*     */       }
/* 353 */       if ((this.dayMask & 0x8) == 8L) {
/* 354 */         this.dayOfWeekMask.add(DayOfWeek.WE);
/*     */       }
/* 356 */       if ((this.dayMask & 0x10) == 16L) {
/* 357 */         this.dayOfWeekMask.add(DayOfWeek.TH);
/*     */       }
/* 359 */       if ((this.dayMask & 0x20) == 32L) {
/* 360 */         this.dayOfWeekMask.add(DayOfWeek.FR);
/*     */       }
/* 362 */       if ((this.dayMask & 0x40) == 64L) {
/* 363 */         this.dayOfWeekMask.add(DayOfWeek.SA);
/*     */       }
/*     */     }
/* 366 */     return this.dayOfWeekMask;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public long getFirstDateTime()
/*     */   {
/* 373 */     return this.firstDateTime;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public List<DateTime> getExdates()
/*     */   {
/* 380 */     if (this.exdateTimes != null) {
/* 381 */       return this.exdateTimes;
/*     */     }
/* 383 */     this.exdateTimes = new ArrayList();
/* 384 */     for (long delSince1601 : this.delMidnightMinsSince1601)
/*     */     {
/*     */ 
/*     */ 
/* 388 */       long minsSince1601 = delSince1601 + this.startTimeOffset;
/* 389 */       boolean canceledInstance = true;
/* 390 */       for (ChangedInstanceInfo cInst : this.changedInstances) {
/* 391 */         if (minsSince1601 == cInst.getOrigStartMinsSince1601()) {
/* 392 */           EnumSet<ExceptionInfoOverrideFlag> overrideFlags = cInst.getOverrideFlags();
/*     */           
/*     */ 
/* 395 */           if ((overrideFlags != null) && (!overrideFlags.isEmpty())) {
/* 396 */             canceledInstance = false;
/* 397 */             break;
/*     */           }
/*     */         }
/*     */       }
/* 401 */       if (canceledInstance) {
/* 402 */         this.exdateTimes.add(IcalUtil.localMinsSince1601toDate(minsSince1601, this.tzDef));
/*     */       }
/*     */     }
/*     */     
/* 406 */     return this.exdateTimes;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public List<DateTime> getRdates()
/*     */   {
/* 415 */     if (this.rdateTimes != null) {
/* 416 */       return this.rdateTimes;
/*     */     }
/* 418 */     this.rdateTimes = new ArrayList();
/* 419 */     for (ChangedInstanceInfo cInst : this.changedInstances) {
/* 420 */       EnumSet<ExceptionInfoOverrideFlag> overrideFlags = cInst.getOverrideFlags();
/*     */       
/*     */ 
/* 423 */       if ((overrideFlags == null) || (overrideFlags.isEmpty())) {
/* 424 */         this.rdateTimes.add(cInst.getStartDate());
/*     */       }
/*     */     }
/* 427 */     return this.rdateTimes;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public List<ChangedInstanceInfo> getChangedInstances()
/*     */   {
/* 434 */     return this.changedInstances;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Property icalRecurrenceProperty(boolean isAllDay, boolean isFloating)
/*     */     throws ServiceException
/*     */   {
/* 446 */     RRule theRule = null;
/* 447 */     if (!this.calScale.isSolarCalendar()) {
/* 448 */       throw TNEFtoIcalendarServiceException.NON_SOLAR_CALENDAR();
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 453 */     StringBuffer recurrenceRule = new StringBuffer("FREQ=");
/*     */     
/*     */ 
/*     */ 
/* 457 */     String weekStartDay = this.firstDayOfWeek.toString();
/* 458 */     boolean hasBYDAY = false;
/* 459 */     boolean isYearly = false;
/* 460 */     int interval = 1;
/* 461 */     switch (this.patternType) {
/*     */     case DAY: 
/* 463 */       recurrenceRule.append("DAILY");
/* 464 */       interval = Long.valueOf(this.period).intValue() / 1440;
/* 465 */       break;
/*     */     case WEEK: 
/* 467 */       recurrenceRule.append("WEEKLY");
/* 468 */       interval = Long.valueOf(this.period).intValue();
/* 469 */       hasBYDAY = true;
/* 470 */       break;
/*     */     case MONTH: 
/* 472 */       interval = Long.valueOf(this.period).intValue();
/* 473 */       if (interval % 12 == 0) {
/* 474 */         isYearly = true;
/* 475 */         recurrenceRule.append("YEARLY");
/* 476 */         interval /= 12;
/*     */       } else {
/* 478 */         recurrenceRule.append("MONTHLY");
/*     */       }
/* 480 */       if (this.dayOfMonth != 0L) {
/* 481 */         recurrenceRule.append(";BYMONTHDAY=");
/* 482 */         if (this.dayOfMonth == 31L) {
/* 483 */           recurrenceRule.append("-1");
/*     */         } else {
/* 485 */           recurrenceRule.append(this.dayOfMonth);
/*     */         }
/*     */       }
/* 488 */       if (isYearly) {
/* 489 */         java.util.TimeZone javaTZ = null;
/* 490 */         if (this.tzDef != null) {
/* 491 */           javaTZ = this.tzDef.getTimeZone();
/*     */         } else {
/* 493 */           javaTZ = net.fortuna.ical4j.model.TimeZone.getTimeZone("Etc/UTC");
/*     */         }
/* 495 */         Date bymonthDate = IcalUtil.localMinsSince1601toDate(this.firstDateTime, this.tzDef);
/* 496 */         Calendar bymonthCal = new GregorianCalendar(javaTZ);
/* 497 */         bymonthCal.setTimeInMillis(bymonthDate.getTime());
/* 498 */         String MONTH_ONLY_PATTERN = "MM";
/* 499 */         DateFormat monthOnlyFormat = new SimpleDateFormat(MONTH_ONLY_PATTERN);
/* 500 */         monthOnlyFormat.setCalendar(bymonthCal);
/* 501 */         recurrenceRule.append(";BYMONTH=");
/* 502 */         recurrenceRule.append(monthOnlyFormat.format(bymonthDate)); }
/* 503 */       break;
/*     */     
/*     */     case MONTH_NTH: 
/* 506 */       interval = Long.valueOf(this.period).intValue();
/* 507 */       if (interval % 12 == 0) {
/* 508 */         isYearly = true;
/* 509 */         recurrenceRule.append("YEARLY");
/* 510 */         interval /= 12;
/*     */       } else {
/* 512 */         recurrenceRule.append("MONTHLY");
/*     */       }
/* 514 */       hasBYDAY = true;
/* 515 */       recurrenceRule.append(";BYSETPOS=");
/* 516 */       if (this.weekDayOccurrenceNumber == 5L) {
/* 517 */         recurrenceRule.append(-1);
/*     */       } else {
/* 519 */         recurrenceRule.append(this.weekDayOccurrenceNumber);
/*     */       }
/* 521 */       if (isYearly) {
/* 522 */         java.util.TimeZone javaTZ = null;
/* 523 */         if (this.tzDef != null) {
/* 524 */           javaTZ = this.tzDef.getTimeZone();
/*     */         } else {
/* 526 */           javaTZ = net.fortuna.ical4j.model.TimeZone.getTimeZone("Etc/UTC");
/*     */         }
/* 528 */         Date bymonthDate = IcalUtil.localMinsSince1601toDate(this.firstDateTime, this.tzDef);
/* 529 */         Calendar bymonthCal = new GregorianCalendar(javaTZ);
/* 530 */         bymonthCal.setTimeInMillis(bymonthDate.getTime());
/* 531 */         String MONTH_ONLY_PATTERN = "MM";
/* 532 */         DateFormat monthOnlyFormat = new SimpleDateFormat(MONTH_ONLY_PATTERN);
/* 533 */         monthOnlyFormat.setCalendar(bymonthCal);
/* 534 */         recurrenceRule.append(";BYMONTH=");
/* 535 */         recurrenceRule.append(monthOnlyFormat.format(bymonthDate)); }
/* 536 */       break;
/*     */     
/*     */     case MONTH_END: 
/*     */     case HJ_MONTH: 
/*     */     case HJ_MONTH_END: 
/*     */     case HJ_MONTH_NTH: 
/* 542 */       throw TNEFtoIcalendarServiceException.UNSUPPORTED_RECURRENCE_TYPE(this.patternType.name());
/*     */     default: 
/* 544 */       throw TNEFtoIcalendarServiceException.UNSUPPORTED_RECURRENCE_TYPE(this.patternType.name());
/*     */     }
/* 546 */     if (recurrenceRule.length() > 5) {
/* 547 */       if (this.endType.equals(EndType.END_AFTER_N_OCCURRENCES)) {
/* 548 */         recurrenceRule.append(";COUNT=");
/* 549 */         recurrenceRule.append(this.occurrenceCount);
/* 550 */       } else if (this.endType.equals(EndType.END_BY_DATE))
/*     */       {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 567 */         long minsSince1601 = this.endMinsSince1601 + this.startTimeOffset;
/* 568 */         DateTime untilDateTime = IcalUtil.localMinsSince1601toDate(minsSince1601, this.tzDef);
/* 569 */         recurrenceRule.append(";UNTIL=");
/* 570 */         java.util.TimeZone untilTZ = null;
/* 571 */         if (this.tzDef != null) {
/* 572 */           untilTZ = this.tzDef.getTimeZone();
/*     */         }
/* 574 */         if (isFloating)
/*     */         {
/* 576 */           recurrenceRule.append(IcalUtil.iCalDateTimeValue(untilDateTime, untilTZ, isAllDay));
/*     */ 
/*     */         }
/* 579 */         else if (isAllDay) {
/* 580 */           recurrenceRule.append(IcalUtil.iCalDateTimeValue(untilDateTime, untilTZ, isAllDay));
/*     */         }
/*     */         else
/*     */         {
/* 584 */           recurrenceRule.append(IcalUtil.icalUtcTime(minsSince1601, this.tzDef));
/*     */         }
/*     */       }
/*     */       
/* 588 */       if (hasBYDAY) {
/* 589 */         WeekDayList weekDayList = new WeekDayList();
/* 590 */         this.dayOfWeekMask = getDayOfWeekMask();
/* 591 */         for (DayOfWeek dow : this.dayOfWeekMask) {
/* 592 */           weekDayList.add(dow.iCal4JWeekDay());
/*     */         }
/* 594 */         if (!weekDayList.isEmpty()) {
/* 595 */           recurrenceRule.append(";BYDAY=");
/* 596 */           recurrenceRule.append(weekDayList);
/*     */         }
/*     */       }
/* 599 */       if (interval != 1) {
/* 600 */         recurrenceRule.append(";INTERVAL=");
/* 601 */         recurrenceRule.append(interval);
/*     */       }
/* 603 */       if (weekStartDay != null) {
/* 604 */         recurrenceRule.append(";WKST=");
/* 605 */         recurrenceRule.append(weekStartDay);
/*     */       }
/*     */       Recur recur;
/*     */       try {
/* 609 */         recur = new Recur(recurrenceRule.toString());
/*     */       } catch (ParseException ex) {
/* 611 */         throw TNEFtoIcalendarServiceException.RRULE_PARSING_PROBLEM(ex);
/*     */       }
/* 613 */       theRule = new RRule(recur);
/*     */     }
/* 615 */     return theRule;
/*     */   }
/*     */   
/*     */   private void readRecurrenceFrequency(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 619 */     int mapiFrequency = ris.readU16();
/*     */     
/* 621 */     for (RecurrenceFrequency curr : RecurrenceFrequency.values()) {
/* 622 */       if (curr.mapiPropValue() == mapiFrequency) {
/* 623 */         this.recurrenceFrequency = curr;
/* 624 */         return;
/*     */       }
/*     */     }
/*     */     
/* 628 */     throw TNEFtoIcalendarServiceException.RECURDEF_BAD_FREQ("0x" + Integer.toHexString(mapiFrequency));
/*     */   }
/*     */   
/*     */   private void readPatternType(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 632 */     int pattType = ris.readU16();
/*     */     
/* 634 */     for (PatternType curr : PatternType.values()) {
/* 635 */       if (curr.mapiPropValue() == pattType) {
/* 636 */         this.patternType = curr;
/* 637 */         return;
/*     */       }
/*     */     }
/*     */     
/* 641 */     throw TNEFtoIcalendarServiceException.RECURDEF_BAD_PATTERN("0x" + Integer.toHexString(pattType));
/*     */   }
/*     */   
/*     */   private void readMsCalScale(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 645 */     int calType = ris.readU16();
/*     */     
/* 647 */     if (calType == 0) {
/* 648 */       if (this.patternType.equals(PatternType.HJ_MONTH)) {
/* 649 */         this.calScale = MsCalScale.HIJRI;
/*     */         
/* 651 */         return;
/*     */       }
/* 653 */       if (this.patternType.equals(PatternType.HJ_MONTH_NTH)) {
/* 654 */         this.calScale = MsCalScale.HIJRI;
/* 655 */         return;
/*     */       }
/*     */     }
/* 658 */     for (MsCalScale curr : MsCalScale.values()) {
/* 659 */       if (curr.mapiPropValue() == calType) {
/* 660 */         this.calScale = curr;
/* 661 */         return;
/*     */       }
/*     */     }
/*     */     
/* 665 */     throw TNEFtoIcalendarServiceException.RECURDEF_BAD_MSCALSCALE("0x" + Integer.toHexString(calType));
/*     */   }
/*     */   
/*     */   private void readEndType(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 669 */     long endTyp = ris.readU32();
/*     */     
/* 671 */     for (EndType curr : EndType.values()) {
/* 672 */       if (curr.mapiPropValue() == endTyp) {
/* 673 */         if (curr.equals(EndType.NEVER_END_OLD)) {
/* 674 */           this.endType = EndType.NEVER_END;
/*     */         } else {
/* 676 */           this.endType = curr;
/*     */         }
/* 678 */         return;
/*     */       }
/*     */     }
/*     */     
/* 682 */     throw TNEFtoIcalendarServiceException.RECURDEF_BAD_ENDTYPE("0x" + Long.toHexString(endTyp));
/*     */   }
/*     */   
/*     */   private void readFirstDayOfWeek(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 686 */     long dow = ris.readU32();
/*     */     
/* 688 */     for (DayOfWeek curr : DayOfWeek.values()) {
/* 689 */       if (curr.mapiPropValue() == dow) {
/* 690 */         this.firstDayOfWeek = curr;
/* 691 */         return;
/*     */       }
/*     */     }
/*     */     
/* 695 */     throw TNEFtoIcalendarServiceException.RECURDEF_BAD_1ST_DOW("0x" + Long.toHexString(dow));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void readFirstDateTime(RawInputStream ris)
/*     */     throws IOException
/*     */   {
/* 708 */     this.firstDateTime = ris.readU32();
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 713 */     StringBuffer buf = new StringBuffer("PidLidAppointmentRecur\n");
/* 714 */     if (this.readerVersion != 12292L) {
/* 715 */       buf.append("    Unexpected ReaderVersion=").append(this.readerVersion).append("\n");
/*     */     }
/*     */     
/* 718 */     if (this.writerVersion != 12292L) {
/* 719 */       buf.append("    Unexpected WriterVersion=").append(this.writerVersion).append("\n");
/*     */     }
/*     */     
/* 722 */     buf.append("    RecurFrequency=").append(getRecurrenceFrequency()).append("\n");
/*     */     
/* 724 */     buf.append("    PatternType=").append(getPatternType()).append("\n");
/*     */     
/* 726 */     buf.append("    MsCalScale=").append(getMsCalScale()).append("\n");
/*     */     
/* 728 */     buf.append("    FirstDateTime=").append(getFirstDateTime()).append("\n");
/*     */     
/* 730 */     buf.append("    Period=").append(this.period).append("\n");
/*     */     
/* 732 */     buf.append("    SlidingFlag=").append(this.slidingFlag).append("\n");
/*     */     
/* 734 */     if (this.haveDayMask) {
/* 735 */       this.dayOfWeekMask = getDayOfWeekMask();
/* 736 */       buf.append("    dayMask=0x").append(Long.toHexString(this.dayMask)).append(" - ").append(this.dayOfWeekMask).append("\n");
/*     */     }
/*     */     
/*     */ 
/* 740 */     if (this.haveDayOfMonth) {
/* 741 */       buf.append("    dayOfMonth=").append(this.dayOfMonth).append("\n");
/*     */     }
/*     */     
/* 744 */     if (this.haveWeekDayOccurNum) {
/* 745 */       buf.append("    weekDayOccurrenceNumber=").append(this.weekDayOccurrenceNumber).append("\n");
/*     */     }
/*     */     
/* 748 */     buf.append("    EndType=").append(getEndType()).append("\n");
/*     */     
/* 750 */     buf.append("    occurrenceCount=").append(this.occurrenceCount).append("\n");
/*     */     
/* 752 */     buf.append("    firstDayOfWeek=").append(getFirstDayOfWeek()).append("\n");
/*     */     
/* 754 */     buf.append("    DeletedInstanceCount=").append(this.deletedInstanceCount).append("\n");
/*     */     
/* 756 */     for (long since1601 : this.delMidnightMinsSince1601) {
/* 757 */       long timeSince1601 = since1601 + this.startTimeOffset;
/* 758 */       String suffix = new String("");
/* 759 */       if (this.changedInstances != null) {
/* 760 */         for (ChangedInstanceInfo cInst : this.changedInstances) {
/* 761 */           if (cInst.getOrigStartMinsSince1601() == timeSince1601) {
/* 762 */             EnumSet<ExceptionInfoOverrideFlag> overrideFlags = cInst.getOverrideFlags();
/* 763 */             if ((overrideFlags == null) || (overrideFlags.isEmpty())) {
/* 764 */               suffix = new String(" [changed - exdate/rdate]"); break;
/*     */             }
/* 766 */             suffix = new String(" [changed - exception]");
/*     */             
/* 768 */             break;
/*     */           }
/*     */         }
/*     */       }
/* 772 */       infoOnLocalTimeSince1601ValWithOffset(buf, "        DeletedInstance=", since1601, this.startTimeOffset, suffix);
/*     */     }
/*     */     
/* 775 */     buf.append("    ModifedInstanceCount=").append(this.modifiedInstanceCount).append("\n");
/*     */     
/* 777 */     for (long since1601 : this.modMidnightMinsSince1601) {
/* 778 */       infoOnLocalTimeSince1601ValWithOffset(buf, "        ModifiedInstance=", since1601, this.startTimeOffset, "");
/*     */     }
/*     */     
/* 781 */     infoOnLocalTimeSince1601Val(buf, "    StartDate=", this.startMinsSince1601);
/*     */     
/* 783 */     infoOnLocalTimeSince1601Val(buf, "    Last Instance's start=", this.endMinsSince1601);
/*     */     
/* 785 */     buf.append("    ReaderVersion2=0x").append(Long.toHexString(this.readerVersion2));
/*     */     
/* 787 */     if ((this.readerVersion2 != 12294L) && (this.readerVersion2 != 0L)) {
/* 788 */       buf.append(" [ODD expected 0x3006 for event or 0x0 for task]");
/*     */     }
/* 790 */     buf.append("\n");
/* 791 */     buf.append("    WriterVersion2=0x").append(Long.toHexString(this.writerVersion2));
/*     */     
/* 793 */     if (this.writerVersion2 == 12294L) {
/* 794 */       buf.append(" [OL2000 style]");
/* 795 */     } else if (this.writerVersion2 == 12295L) {
/* 796 */       buf.append(" [OLXP style]");
/* 797 */     } else if (this.writerVersion2 == 12296L) {
/* 798 */       buf.append(" [OL2003 style]");
/* 799 */     } else if (this.writerVersion2 == 12297L) {
/* 800 */       buf.append(" [OL2007 style]");
/*     */     }
/* 802 */     buf.append("\n");
/* 803 */     buf.append("    StartTimeOffset=").append(this.startTimeOffset).append("\n");
/* 804 */     buf.append("    EndTimeOffset=").append(this.endTimeOffset).append("\n");
/* 805 */     buf.append("    ExceptionCount=").append(this.exceptionCount).append("\n");
/* 806 */     if (this.changedInstances != null) {
/* 807 */       for (ChangedInstanceInfo cInst : this.changedInstances) {
/* 808 */         buf.append(cInst.toString());
/*     */       }
/*     */     }
/* 811 */     if (this.rsrvdBlock1Size != -1L) {
/* 812 */       buf.append("    rsrvdBlock1Size=").append(this.rsrvdBlock1Size).append("\n");
/* 813 */       buf.append("    rsrvdBlock1=").append(TNEFUtils.toHexString(this.rsrvdBlock1, (int)this.rsrvdBlock1Size)).append("\n");
/*     */     }
/*     */     
/*     */ 
/* 817 */     if (this.rsrvdBlock2Size != -1L) {
/* 818 */       buf.append("    rsrvdBlock2Size=").append(this.rsrvdBlock2Size).append("\n");
/* 819 */       buf.append("    rsrvdBlock2=").append(TNEFUtils.toHexString(this.rsrvdBlock2, (int)this.rsrvdBlock2Size)).append("\n");
/*     */     }
/*     */     
/*     */ 
/* 823 */     if (this.unprocessedByteCount != 0L) {
/* 824 */       buf.append("    unprocessedByteCount=").append(this.unprocessedByteCount).append("\n");
/* 825 */       buf.append("    unprocessedBytes=").append(TNEFUtils.toHexString(this.unprocessedBytes, (int)this.unprocessedByteCount)).append("\n");
/*     */     }
/*     */     
/*     */ 
/* 829 */     return buf.toString();
/*     */   }
/*     */   
/*     */   private StringBuffer infoOnLocalTimeSince1601Val(StringBuffer buf, String desc, long localTimeSince1601)
/*     */   {
/* 834 */     buf.append(desc);
/* 835 */     buf.append(IcalUtil.friendlyLocalTime(localTimeSince1601, this.tzDef));
/* 836 */     buf.append(" (").append(IcalUtil.icalUtcTime(localTimeSince1601, this.tzDef));
/* 837 */     buf.append(") [");
/* 838 */     buf.append(localTimeSince1601);
/* 839 */     buf.append(" (0x");
/* 840 */     buf.append(Long.toHexString(localTimeSince1601));
/* 841 */     buf.append(")]\n");
/* 842 */     return buf;
/*     */   }
/*     */   
/*     */   private StringBuffer infoOnLocalTimeSince1601ValWithOffset(StringBuffer buf, String desc, long localTimeSince1601, long startOffset, String suffix)
/*     */   {
/* 847 */     long since1601 = localTimeSince1601 + startOffset;
/* 848 */     buf.append(desc);
/* 849 */     buf.append(IcalUtil.friendlyLocalTime(since1601, this.tzDef));
/* 850 */     buf.append(" (").append(IcalUtil.icalUtcTime(since1601, this.tzDef));
/* 851 */     buf.append(") [");
/* 852 */     buf.append(localTimeSince1601);
/* 853 */     buf.append(" + ");
/* 854 */     buf.append(startOffset);
/* 855 */     buf.append("]");
/* 856 */     buf.append(suffix);
/* 857 */     buf.append("\n");
/* 858 */     return buf;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/tnef/mapi/RecurrenceDefinition.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */